package com.cskaoyan.app.controller;

import com.cskaoyan.app.bean.bo.AdminIssueCreateBO;
import com.cskaoyan.app.bean.bo.AdminIssueUpdateBO;
import com.cskaoyan.app.bean.common.BasePageInfo;
import com.cskaoyan.app.bean.common.BaseRespVo;
import com.cskaoyan.app.bean.common.CommonData;
import com.cskaoyan.app.bean.po.MarketIssue;
import com.cskaoyan.app.service.AdminIssueService;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Shuuka
 * @email 1712430536@qq.com
 * @date 2022/12/29 20:19
 */
@RestController
@RequestMapping("admin/issue")
public class AdminIssueController {

    @Autowired
    AdminIssueService adminIssueService;

    @GetMapping("list")
    public BaseRespVo<CommonData<MarketIssue>> list(BasePageInfo basePageInfo, String question){
        CommonData<MarketIssue> data = adminIssueService.list(basePageInfo,question);
        return BaseRespVo.ok(data);
    }

    @PostMapping("update")
    public BaseRespVo<Object> update(@RequestBody @Validated AdminIssueUpdateBO adminIssueUpdateBO){
        MarketIssue marketIssue = adminIssueService.update(adminIssueUpdateBO);
        if(marketIssue == null){
            return BaseRespVo.invalidData("更新失败");
        }
        return BaseRespVo.ok(marketIssue);
    }

    @PostMapping("create")
    public BaseRespVo<Object> create(@RequestBody @Validated AdminIssueCreateBO adminIssueCreateBO){
        MarketIssue marketIssue = adminIssueService.create(adminIssueCreateBO);
        if(marketIssue == null){
            return BaseRespVo.invalidData("新增失败");
        }
        return BaseRespVo.ok(marketIssue);
    }

    @PostMapping("delete")
    public BaseRespVo<Object> delete(@RequestBody MarketIssue marketIssue){
        Integer row = adminIssueService.delete(marketIssue);
        if(row != 1){
            return BaseRespVo.invalidData("删除失败");
        }
        return BaseRespVo.ok();
    }


}
